package com.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.Review;
import com.example.domain.model.ReviewDTO;
import com.example.service.ReviewService;
import com.example.mapper.ReviewMapper;
import com.example.util.SensitiveWordFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【review】的数据库操作Service实现
* @createDate 2023-03-20 09:46:32
*/
@Service
public class ReviewServiceImpl extends ServiceImpl<ReviewMapper, Review> implements ReviewService{
    @Autowired
    private ReviewMapper reviewMapper;

    @Autowired
    private SensitiveWordFilter sensitiveWordFilter;
    @Override
    public IPage<ReviewDTO> getMyList(String userId, Page<ReviewDTO> page) {
        return reviewMapper.selectPage(page,userId);
    }

    @Override
    public IPage<ReviewDTO> getList(String movieId, Page<ReviewDTO> page) {
        return reviewMapper.selectByMovieIdPage(page,movieId);
    }

    @Override
    public IPage<ReviewDTO> getAllList(Page<ReviewDTO> page) {

        return reviewMapper.selectPage(page,null);
    }

    @Override
    public Review getById(String id) {
        return reviewMapper.selectById(id);
    }

    @Override
    public boolean save(Review review,String userId) {
        review.setUserId(userId);
        String re = sensitiveWordFilter.filter(review.getComment());
        review.setComment(re);
        return reviewMapper.insert(review) > 0;
    }

    @Override
    public boolean update(String id, Review review) {
        Review review1 = reviewMapper.selectById(id);
        if (review1 != null){
            review.setId(id);
            return reviewMapper.updateById(review) > 0;
        }
        return false;
    }

    @Override
    public boolean delete(String id) {
        return reviewMapper.deleteById(id) > 0;
    }
}




